<?php
set_include_path ( $_SERVER ['DOCUMENT_ROOT'] );
include_once 'admin/includes/functions/admin-functions.php';
global $DBobject;

if(empty($_SESSION['user']['admin'])){
  echo json_encode(array(
      'classterm' =>  0,
      'term' =>  0
  ));
  die();
}

$referer = parse_url($_SERVER['HTTP_REFERER']);
if($referer['host'] == $GLOBALS['HTTP_HOST'] && !empty($_SESSION['user']['admin']['id']) ){
	if (!empty($_POST['term_id'])) {
		$classterm = array();
		$sql = "SELECT * FROM tbl_classterm WHERE classterm_deleted IS NULL AND classterm_term_id = :id AND classterm_published = '1'";
		if($res = $DBobject->wrappedSql($sql, array(':id'=>$_POST['term_id']))){
			foreach($res as $r){
				$classterm["{$r['classterm_class_id']}"] = $r['classterm_published'];
			}
		}
	
		echo json_encode(array(
				'classterm' =>  $classterm,
				'term' =>  $_POST['term_id']
			));
	}
}
